<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>Map Viewer</title>
		<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"></script>
		<script type="text/javascript">
		    var map = null;
		    var route = null;
		    var routeOptimize = null;
		    var routeUnit = null;
		    var routeOptions = null;
		    
		    function GetMap()
			{
			    var center;
				map = new VEMap("mapContainer");
				map.SetDashboardSize(VEDashboardSize.Tiny);
				map.SetTileBuffer(1);
				map.onLoadMap = function()
				{
					//Notify the host that map has been loaded
					window.setTimeout("window.external.MapLoaded()", 0);
				}
				map.AttachEvent("onchangeview", setFormValues);
				map.LoadMap();
				map.ShowDashboard();
			}
			
			function setFormValues()
			{
				window.external.SetCenterCoords(map.GetCenter().Latitude, map.GetCenter().Longitude, map.GetZoomLevel());
			}
			
			function GetRoute(start, end, unit, type)
			{
			    if(unit == "km")
			    {
			        routeUnit = VERouteDistanceUnit.Kilometer;
			    }
			    else
			    {
			        routeUnit = VERouteDistanceUnit.Mile;
			    }
			    
			    if(type == "short")
			    {
			        routeOptimize = VERouteOptimize.MinimizeDistance;
			    }
			    else
			    {
			        routeOptimize = VERouteOptimize.MinimizeTime;
			    }
			    
			    routeOptions = new VERouteOptions;
			    
			    routeOptions.DrawRoute = true;
			    routeOptions.RouteCallback = onGotDirections;
			    routeOptions.DistanceUnit = routeUnit;
			    routeOptions.RouteOptimize = routeOptimize;
			    
			    map.GetDirections([start, end], routeOptions);
			}
			
			function onGotDirections(route)
			{
			    var directions = "";
			    var segments = route.RouteLegs[0].Itinerary.Items;
			    
			    if (segments != undefined)
			    {
			        for (var i = 0; i < segments.length; i++)
			        {
			            directions += segments[i].LatLong.Latitude + "|" + segments[i].LatLong.Longitude + "|" + segments[i].Distance + "|" + segments[i].Text + "\r\n";
			        }
			    }
			    window.external.RouteLoaded(route.Distance + routeOptions.DistanceUnit, route.Time, directions);
			    setFormValues();
			}
			
			function getRoute()
			{
			    return route;
			}
			
			function SetMapStyle(mapStyle)
			{
			    map.SetMapStyle(mapStyle);
			}
		</script>
		<style type="text/css">
		html, body
		{
			margin: 0;
			padding: 0;
			font-family: Tahoma, Arial, sans-serif;
		}
		
		.map
		{
		    width: 640px; 
		    height: 640px;
		}
		</style>
	</head>
	<body onload="GetMap();">
	    <div id="mapContainer" class="map"></div>
	</body>
</html>